<template>
  <div class="app-container">
    <el-form ref="form"
             :model="form"
             :rules="rules"
             :label-position="labelPosition"
             class="register-form">
      <el-row :gutter="40">
        <el-col :span="8">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item prop="reportNo" label="报告文号">
                <el-input v-model="form.reportNo" type="text" auto-complete="off" placeholder="请输入报告文号" readonly/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item prop="customerName" label="客户名称（被审验单位名称）">
                <el-input v-model="form.customerName" type="text" auto-complete="off" placeholder="请输入客户名称（被审验单位名称）" readonly/>
              </el-form-item>
            </el-col>
            <!--   <el-col :span="12" v-judgeAccount="1">
                 <el-form-item prop="firmName" label="事务所名称">
                   <el-input v-model="form.firmName" type="text" auto-complete="off" placeholder="请输入事务所名称" />
                 </el-form-item>
               </el-col>-->
            <el-col :span="12">
              <el-form-item prop="customerBusinessLicense" label="客户营业执照号">
                <el-input v-model="form.customerBusinessLicense" type="text" auto-complete="off" placeholder="请输入客户营业执照号" readonly/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="是否属于证券业务">
                <el-input v-model="form.isSecuritiesBusiness" type="text" readonly/>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item prop="officeRemarks" label="备注（请填写专项审计内容：如'竣工结算专项审计'）">
                <el-input v-model="form.officeRemarks" type="text" auto-complete="off" :placeholder="'请输入'+officeRemarksLable" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="首次承接业务时间">
                <el-input v-model="form.firstBusinessTime" type="text" readonly/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item>
            <el-button
              :loading="loading1"
              size="medium"
              type="primary"
              @click.native.prevent="handleSubmit(1)"
            >
              <span v-if="!loading1">提 交</span>
              <span v-else>提 交 中...</span>
            </el-button>
         <!--   <el-button
              :loading="loading0"
              size="medium"
              type="primary"
              @click.native.prevent="handleSubmit(0)"
              v-hasPermi="['assurance:drafts']"
            >
              <span v-if="!loading0">保 存 草 稿</span>
              <span v-else>保 存 中...</span>
            </el-button>-->
            <el-button
              size="medium"
              type="default"
              @click.native.prevent="handleGoBack"
            >
              <span>返 回</span>
            </el-button>
          </el-form-item>
        </el-col>
        <el-col :span="16">
          <el-row :gutter="20">
            <el-col :span="6">
              <el-form-item label="意见类型">
                <el-input v-model="form.opinionType" type="text" readonly/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="报备类型">
                <el-input v-model="form.reportType" type="text" readonly/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="审计年度">
                <el-input v-model="form.auditYear" type="text" readonly/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="报告日期">
                <el-input v-model="form.reportTime" type="text" readonly/>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="20">
            <el-col :span="6">
              <el-form-item label="收费金额（元）">
                <el-input v-model="form.chargeAmount" type="text" readonly/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="验资金额（元）">
                <el-input v-model="form.capitalVerificationAmount" type="text" readonly/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="验资币种">
                <el-input v-model="form.capitalVerificationCurrency" type="text" readonly/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item prop="placeOfIncorporation"
                            label="公司注册地"
              >
                <el-input v-model="form.placeOfIncorporation" type="text" readonly/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item prop="businessAddress"
                            label="业务所在地"
              >
                <el-input v-model="form.businessAddress" type="text" readonly/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20" v-for="(item, index) in form.assuranceBusinessDataRegisterSignatures" :key="item.registerId">
            <el-col :span="6">
              <el-form-item
                :label="`签字注会${index+1}证书号`"
                :prop="'assuranceBusinessDataRegisterSignatures.' + index + '.registrationCertificateNo'"
              >
                <el-input v-model="item.registrationCertificateNo" type="text" auto-complete="off" placeholder="请输入签字注师证号" readonly/>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item
                :label="`签字注册会计师${index+1}`"
                :prop="'assuranceBusinessDataRegisterSignatures.' + index + '.registrantName'"
              >
                <el-input v-model="item.registrantName" type="text" auto-complete="off" placeholder="请输入签字注师姓名" readonly/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
  import { addAssurance,saveDraft,getAssurance,checkFirmName } from "@/api/system/assurance";
  import store from '@/store'
  export default {
    name: "updateRemarks",
    data() {
      return {
        businessId: this.$route.query.businessId, // 传过来的 id
        labelPosition: "top",
        reportTypeOption: [], // 报备类型
        currencyTypeOption: [], // 验资币种
        opinionTypeOption: [], // 意见类型
        addressPronOption:[],//业务所在地，公司注册地 数据
        form: {
          assuranceBusinessDataRegisterSignatures:[
            {
              registrantName: '',
              registrationCertificateNo: ''
            },
            {
              registrantName: '',
              registrationCertificateNo: ''
            },
          ]
        },
        rules: {
          officeRemarks:[{ required: true, trigger: "blur", message: "请填写专项审计业务内容，如'竣工结算专项审计'"}]
        },
        loading0: false, // 草稿
        loading1: false, // 提交
        redirect: undefined,
        officeRemarksLable:"备注",
      };
    },
    created() {
      this.getDicts("report_type").then(response => {
        // 报备类型
        this.reportTypeOption = response.data;
      });
      this.getDicts("currency").then(response => {
        // 验资币种
        this.currencyTypeOption = response.data
      });
      this.getDicts("type_of_opinion").then(response => {
        // 意见类型
        this.opinionTypeOption = response.data
      });
      this.getDicts("business_address_pron").then(response => {
        this.addressPronOption = response.data
      });

      if(this.businessId){
        this.getDetail(this.businessId);
      }
    },
    deactivated () { //清除keep-alive的缓存
      this.$destroy(true)
    },
    methods: {
      getDetail(businessId){
        getAssurance(businessId).then(
          response => {
            if(response.msg && response.msg == "无权限"){
              this.$message({
                message: "无权限!",
                type: 'error'
              });
              this.$router.push("/assurance/list")
            }else {
              this.form = response.data;
            }
          }
        );
      },
      handleSubmit(status) {
        this.$refs.form.validate(valid => {
          if (valid) {
            let messageTitle;
            status === 0 ? this.loading0 = true : this.loading1 = true
            status === 0 ? messageTitle = '保存草稿' : messageTitle = '提交' // 0草稿，1保存，2删除
            this.form.status = status
            if(status===0){
              saveDraft(this.form).then(
                response => {
                  this.$confirm(`${messageTitle}成功`, '提示', {
                    confirmButtonText: '返回',
                    showClose: false,
                    showCancelButton: false,
                    type: 'success'
                  }).then(() => {
                    status === 0 ? this.loading0 = false : this.loading1 = false;
                    this.$router.go(-1);
                  });
                }
              ).catch(()=>{
                status === 0 ? this.loading0 = false : this.loading1 = false;
              });
            }else{
              addAssurance(this.form).then(
                response => {
                  this.$confirm(`${messageTitle}成功`, '提示', {
                    confirmButtonText: '返回',
                    showClose: false,
                    showCancelButton: false,
                    type: 'success'
                  }).then(() => {
                    status === 0 ? this.loading0 = false : this.loading1 = false;
                    this.$router.go(-1);
                  });
                }
              ).catch(()=>{
                status === 0 ? this.loading0 = false : this.loading1 = false;
              });
            }
          }
        });
      },
      handleGoBack() {
        this.$router.go(-1);
      },
      addData() {
        this.form.assuranceBusinessDataRegisterSignatures.push({
          registrantName: '',
          registrationCertificateNo: ''
        },);
      },
      removeData(item) {
        let index = this.form.assuranceBusinessDataRegisterSignatures.indexOf(item)
        if (index !== -1) {
          this.form.assuranceBusinessDataRegisterSignatures.splice(index, 1)
        }
      },
    }
  };
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
  ::v-deep .el-form-item__label{
    position: relative;
    font-size: 15px;
  }
  ::v-deep .el-form-item.is-required:not(.is-no-asterisk)>.el-form-item__label:before {
    content: '';  // 去掉 * 号
  }
  ::v-deep .el-form-item.is-required:not(.is-no-asterisk)>.el-form-item__label:after {
    content: '*';  // 后置 * 号
    color: #ff4949;
    margin-right: 4px;
    right: -15px;
    top: 2px;
    position: absolute;
  }
  ::v-deep .el-input__inner{
    &::-webkit-input-placeholder {
      font-size: 13px;
    }
  }
  ::v-deep .el-date-editor.el-input, ::v-deep .el-select{
    width: 100%;
  }
  .btnPosition{
    display: inline-block;
    text-align: center;
    height: 36px;
    line-height: 36px;
    padding: 0 16px;
    cursor: pointer;
    border-radius: 4px;
    color: #848ae3;
    font-size: 18px;
    font-weight: 900;
    border: 1px solid rgba(132,138,227,.3);
    background: #fff;
    &:hover{
      border: 1px solid rgba(132,138,227,.9);
    }
  }
  .poBtn{
    margin-top: 50px;
    display: block;
    text-align: center
  }
</style>
